<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<%@ include file="validOwner.jsp" %>
<% List<Distribute> distributes= new ArrayList<Distribute>(); %>
<% List<Supplier> suppliers=(List<Supplier>) session.getAttribute("suppliers");  
  List<Machine> machines= ( List<Machine> )session.getAttribute("machines"); %>
<link href="<%=request.getContextPath()%>/styles/table.css" rel="stylesheet" type="text/css" />
</head>
<body>
 <% boolean success; 
    Object temp =request.getAttribute("success");
     if(temp==null){  success=false; }else{  success= (Boolean) temp; }
    if(success) {
               request.removeAttribute("success");
     distributes= ( List<Distribute>) request.getSession().getAttribute("distributes");
        }
  %>
<h1 align="center">分配管理</h1>    
  
        <form action="<%=basePath%>/owner4Jsp" >
    <input type="hidden" name="affair" value="searchDistribute" />
    商家：<select name="supplier"> 
     <option value="" > 全部 </option>
    <% for(int i=0;i<suppliers.size();i++){ %>
    <option value="<%=suppliers.get(i).getTelnum() %>" > <%=suppliers.get(i).getName() %> </option> 
    <%} %>
      </select> 
     自提柜： <select name="machine" style="display: inline;" > 
     <option value="0"> 全部 </option>
       <% for(int i=0;i<machines.size();i++){ %>
    <option value="<%=machines.get(i).getId() %>" > <%=machines.get(i).getName() %> </option> 
    <%} %>
      </select> 
     时间 ： <select  name="time" style="display: inline;" > 
     <option value="0" > 全部 </option>
       <option value="1" > 早班 </option> 
        <option value="2" > 中班 </option> 
         <option value="3" > 晚班 </option> 
       </select> 
    <input type="submit" value="搜索"> <br/>
    </form> 
   
<table width="100%" class="tableA">
 <tr>  
 <th width="25%"  style="BACKGROUND-COLOR: #FF0000" >商家</th> 
   <th width="25%" style="BACKGROUND-COLOR: #FF0000"> 自提柜</th>  
    <th width="25%" style="BACKGROUND-COLOR: #FF0000"  >时间</th> 
      <th width="25%" style="BACKGROUND-COLOR: #FF0000"  >操作</th> 
     </tr> 

<%!String timeWord="时间不合法";  %>
<%!String machineName="名称未赋值";  %>
<%!String supplierName="名称未赋值";  %>

<%        for (int i = 0; i < distributes.size(); i++) {     
             pageContext.setAttribute("distribute", distributes.get(i));  
               if(distributes.get(i).getTimeFlag()==1) timeWord="早班";
               if(distributes.get(i).getTimeFlag()==2) timeWord="中班";
               if(distributes.get(i).getTimeFlag()==3) timeWord="晚班";  
                int machineid= distributes.get(i).getMachine();      
                for(int j=0;j<machines.size();j++){
                 if(machineid==machines.get(j).getId()){machineName=machines.get(j).getName(); break; }
                }   
                String supplierTelnum= distributes.get(i).getSupplier(); 
                for(int j=0;j<suppliers.size();j++){
                 if(supplierTelnum.equals(suppliers.get(j).getTelnum())){ supplierName=suppliers.get(j).getName();break; }
                }      
                pageContext.setAttribute("row", i % 2 != 0 ? "odd" : "even"); %>           
                       <tr>           
                                    <td> <%=supplierName %> </td>               
                                    <td><%=machineName %></td>    
                                    <td><%=timeWord %></td>        
                                   
                       <td>
                  
                        <a href="<%=request.getContextPath()%>/programmer4Jsp?affair=deleteDistribute&supplier=${distribute.supplier}&machine=${distribute.machine}&time=${distribute.time}">删除</a></td>           
                             </tr> 
<%} %>
  
 </table>  
 <br/>   <br/>   <br/>  
</body>
</html>
<script> 
//取出传回来的参数error并与yes比较
  var errorInfoA ='<%=request.getParameter("errorInfo")%>';
  var  errorInfo=decodeURI(errorInfoA);
  if(errorInfo!='null'){
   alert(errorInfo);}

</script>